home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 14 / Example 14.1 / unit.h < prev   
Encoding:
C/C++ Source or Header  |  2006-07-16  |  2.5 KB  |  89 lines

  1. #ifndef _RTS_UNIT_
  2. #define _RTS_UNIT_
  3.  
  4. #include "skinnedmesh.h"
  5. #include "mapObject.h"
  6.  
  7. void LoadUnitResources(IDirect3DDevice9* m_pDevice);
  8. void UnloadUnitResources();
  9.  
  10. #define STATE_IDLE 0
  11. #define STATE_MOVING 1
  12. #define STATE_DEAD 3
  13. #define STATE_SEARCH 4
  14. #define STATE_ATTACK 5
  15. #define STATE_RETREAT 6
  16. #define STATE_GOTO_BUILD 7
  17. #define STATE_BUILD 8
  18.  
  19. #define WORKER 0
  20. #define SOLDIER 1
  21. #define MAGICIAN 2
  22. #define WARRIOR 1 + rand()%2        //Soldier or Magician
  23.  
  24. //Effect Pool
  25. extern std::vector<EFFECT*> effects;
  26.  
  27. class UNIT : public MAPOBJECT
  28. {
  29.     friend class APPLICATION;
  30.     friend class PLAYER;
  31.     friend class BUILDING;
  32.     friend class MAPOBJECT;
  33.     friend class GROUPAI;
  34.     friend class CONSTRUCT_BUILDING;
  35.     public:
  36.         UNIT(int _type, int _team, INTPOINT mp, TERRAIN *_terrain, PLAYER *_player, IDirect3DDevice9* Dev);
  37.         ~UNIT();
  38.  
  39.         //Abstract functions declared in MAPOBJECT
  40.         void Render();
  41.         void Update(float deltaTime);
  42.         BBOX GetBoundingBox();
  43.         D3DXMATRIX GetWorldMatrix();
  44.  
  45.         //Specific UNIT functions
  46.         void Goto(INTPOINT mp, bool considerUnits, bool _finalGoal, int newState);    //Order unit to mp
  47.         void MoveUnit(INTPOINT to);
  48.         D3DXVECTOR3 GetDirection(INTPOINT p1, INTPOINT p2);
  49.         void SetAnimation(char name[]);
  50.         void SetAnimation(int index);
  51.         bool CheckCollision(INTPOINT mp);
  52.         void Pause(float time);
  53.  
  54.         bool UnitAI(bool newMapTile);
  55.         void Attack(MAPOBJECT *_target);
  56.         void ConstructBuilding(int buildToPlace, INTPOINT pos);
  57.         bool isDead();
  58.         void Damage(int dmg, MAPOBJECT* attacker);
  59.         void Heal();
  60.  
  61.     private:
  62.  
  63.         //Animation variables
  64.         float m_time;                    //This units animation time
  65.         float m_speed;                    //Movement & animation speed
  66.         float m_pauseTime;                //Time to pause
  67.         float m_attackTime;
  68.         float m_mana;
  69.         int m_animation;                    //Current animation, Run, Still, attack etc.
  70.         D3DXVECTOR3 m_rotation, m_scale;    //Used to build the world matrix
  71.         ID3DXAnimationController* m_pAnimControl;    //Animation control
  72.  
  73.         //Status variables
  74.         int m_state;                        //Unit state
  75.         D3DXVECTOR3 m_staffPos;            //Used by magician
  76.         int m_buildingToPlace;            //Used by worker to build building
  77.         INTPOINT m_buildingPosition;        // -------- " --------------
  78.         PLAYER *m_player;
  79.  
  80.         //Movement variables
  81.         INTPOINT m_finalGoal;
  82.         std::vector<INTPOINT> m_path;        //The active path 
  83.         D3DXVECTOR3 m_lastWP, m_nextWP;        //last & next waypoint
  84.         int m_activeWP;                    //active waypoint
  85.         bool m_moving;
  86.         float m_movePrc;                    // 0.0 - 1.0, used to interpolate between m_lastWP & m_nextWP
  87. };
  88.  
  89. #endif